// SPDX-FileCopyrightText: 2023-2025 Sangfor Technologies Inc.
// SPDX-License-Identifier: Mulan PSL v2
package crypto

import (
	"fmt"
	"testing"
)

func encryptDecrypt(cipher *AesCbc, t *testing.T) {
	cases := []string{
		"123456\n\n",
		"123",
		"sangfor",
		"clust_redis_~",
		"clust_redis_~!@#$%",
		"cluster_gz_redis_~!@#$%",
		"(()**&&^&+)_(_)(_)(_8<>?><?//.,,m",
		"123100(()**&&^&*%@~!@#$%^%&&*(^&+)_(_)m",
		"123100(()**&&^&*%@~!@#$%^%&&*(^&+)_(_)(_)??//.,,m",
		"1230(()**&&^&*%@~!@#$%^%&&*(^&+)_(_)(_)(_8<><?//.,,m",
		"123100(()**&&zxcvbnm,jkhfafgaf\\';\\';././,][]*-^&*%@~!@#$%^%&&*(^&+)_(_)(_)(_8<>?><?//.,,m",
	}

	for _, ca := range cases {
		fmt.Println(ca)

		enData := cipher.Encrypt(ca)

		fmt.Println(enData)

		deData, _ := cipher.Decrypt(enData)
		if ca != deData {
			t.Fatal(ca)
		}
	}
}

func TestApi(t *testing.T) {
	cipher, _ := NewAesCbc("sangforxxxxxx")
	encryptDecrypt(cipher, t)
}

func TestSdlApi(t *testing.T) {
	const (
		ASEKey1Path    = "/matrix/etc/conf/152613e1a9c8ceff/7e267b8d2db6c769"
		ASEKey2Path    = "/matrix/etc/conf/19885c245bcba35e/3f3f3159880cf076"
		ASEKey3        = "a9c5d7f6bca306fac4744e1a9c5d7ffa"
		ASEKeySaltPath = "/matrix/etc/conf/7c1829ad/71939c51"
	)

	cipher, _ := NewAesCbcSxf(ASEKey1Path, ASEKey2Path, []byte(ASEKey3), ASEKeySaltPath)
	encryptDecrypt(cipher, t)
}
